package com.lab.webSocket.repository;

import com.lab.webSocket.dto.CheckUserIdReturnDto;
import com.lab.webSocket.dto.UserDto;
import com.lab.webSocket.dto.UserInfoDto;
import com.lab.webSocket.model.UserEntity;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;

import java.util.List;

/**
 * Created by xu_jiaHui on 2017/8/26.
 */
public interface UserRepository extends CrudRepository<UserEntity, Long> {

    /**
     * @Description: 登录检测
     * @author xu_jiaHui
     * @date 2017/8/29 12:53
     */
    public UserDto loginCheck(String userAccount, String userPassword) throws Exception;

    /**
     * @Description: 获取用户名数量 判断是否重复
     * @author xu_jiaHui
     * @date 2017/8/29 12:52
     */
    public CheckUserIdReturnDto checkUserId(String userAccount) throws Exception;

    /**
     * @Description: 通过账号，昵称信息获取用户列表
     * @author xu_jiaHui
     * @date 2017/9/7 15:47
     */
    public List<UserInfoDto> findFriendsByInfo(String info) throws Exception;

    /**
     * @Description: 记录退出时间
     * @author xu_jiaHui
     * @date 2017/9/7 23:24
     */
    @Modifying
    @Query(value = "update UserEntity set userLastLogoutTime=?2 where userAccount=?1")
    public Integer updateLogoutTime(String userAccount, String logoutTime);

    /**
     * @Description: 更新用户信息
     * @author xu_jiaHui
     * @date 2017/9/7 23:24
     */
    @Modifying
    @Query(value = "update UserEntity set userNickname=?2,userSex=?3,userAge=?4,userIcon=?5,userProfile=?6 where userId=?1")
    public Integer updateUserInfo(Integer userId, String userNickname, Integer userSex, Integer userAge, String userIcon, String userProfile) throws Exception;

    /**
     * @Description: 获取用户信息
     * @author xu_jiaHui
     * @date 2017/9/9 20:58
     */
    @Query(value = "select new com.lab.webSocket.dto.UserDto(" +
            "userId,userAccount,userNickname,userSex,userAge,userIcon,userProfile) from UserEntity where userAccount=?1")
    public UserDto getUserInfo(String userAccount) throws Exception;
}
